<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    hello
  </div>
  <script>
    class Dep {
      constructor() {
        this.subs = []
      }
      addDep(sub) {
        if (sub && typeof sub.update === 'function') {
          this.subs.push(sub)
        }
      }
      notify() {
        this.subs.forEach(sub => {
          sub.update()
        })
      }
    }
    class Watcher {
      update() {
        document.getElementById('app').textContent = 'Hello World'
      }
    }
    let dep = new Dep()
    let watcher = new Watcher()
    dep.addDep(watcher)
  </script>
</body>

</html>